﻿Imports System.Data.OleDb
Imports System.IO
Imports System.Threading
Imports System.Data.OleDb.OleDbDataReader
Public Class bookshelf
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If User.Identity.IsAuthenticated = False Then
            Response.Redirect("~/Account/Register.aspx")
        End If
        displayUserBooks()
    End Sub
    Sub displayUserBooks()
        Dim conn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("BookMeetConnString").ConnectionString)
        Dim cmd As OleDbCommand = New OleDbCommand()
        cmd.Connection = conn
        conn.Open()
        Session("currentuser") = User.Identity.Name
        cmd.Parameters.AddWithValue("@currentUser", Session("currentuser"))
        cmd.CommandText = String.Format("SELECT booklist.ID, booklist.Title, booklist.Author, booklist.imgurl, bookshelfjunction.BookID FROM booklist INNER JOIN bookshelfjunction ON bookshelfjunction.BookID = booklist.ID WHERE bookshelfjunction.UserName = @currentUser")
        bookshelfie.DataSource = cmd.ExecuteReader()
        bookshelfie.DataBind()
        conn.Close()
    End Sub
    Protected Sub btnClearBookshelf()
        Dim conn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("BookMeetConnString").ConnectionString)
        Dim cmd As OleDbCommand = New OleDbCommand()
        cmd.Connection = conn
        conn.Open()
        Session("currentuser") = User.Identity.Name
        cmd.Parameters.AddWithValue("@currentUser", Session("currentuser"))
        cmd.CommandText = String.Format("DELETE FROM bookshelfjunction WHERE bookshelfjunction.UserName = @currentUser")
        cmd.ExecuteNonQuery()
        conn.Close()
        displayUserBooks()
    End Sub
    Protected Sub btnGoToList()
        Response.Redirect("~/list.aspx")
    End Sub
End Class